﻿using System.Collections.Generic;
using Microscan.SDK;
using MSDK = Microscan.SDK;

namespace NDK.Module.Model
{
    public class MscBarcod
    {
        //const string DefaultAddr = @"192.168.188.2";
        MSDK.ReaderDevice _reader;
        MSDK.ReaderCycleReportConnection _reportConnection;
        MSDK.ImageOptions _imageOptions;
        readonly MSDK.DeviceDiscovery _discovery = Connector.Instance.Discovery;

        private List<string> _strIp = new List<string>();

        public List<string> strIp
        {
            get {return _strIp;}
            set { _strIp = value; }
        }

        public MscBarcod()
        {
            //UseReader(DefaultAddr);
            DeviceDiscovery.NewDevice += DeviceDiscovery_NewDevice;
            _discovery.StartScan();

        }

        

        private void DeviceDiscovery_NewDevice(UdpDevice dev)
        {
            UpdateDevices();
        }

        private void UpdateDevices()
        {
            var list = _discovery.DeviceList;
            foreach (var dev in list)
            {
                //_strIp.Add(dev.ipAddr.ToString());
                if (!_strIp.Contains(dev.ipAddr.ToString()))
                {
                    _strIp.Add(dev.ipAddr.ToString());
                }
            }
        }
    }
}
